package org.jgs1904;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

import java.io.IOException;

/**
 * @author 墨苍璃
 * @date 2023年06月04日21时56分
 */
public class HelloElasticsearch {

    public static void main(String[] args) throws IOException {
        // 创建客户端对象
        // Create the low-level client
        RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();

        // Create the transport with a Jackson mapper
        ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());

        // And create the API client
        ElasticsearchClient client = new ElasticsearchClient(transport);

        System.out.println(restClient);
        System.out.println(client);

        // 关闭客户端连接
        transport.close();
        restClient.close();
    }


}
